package com.tx.blog.util;

import com.tx.blog.user.vo.UserVo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class HttpUtil {

    public static final String USER_KEY = "user";

    public static HttpSession getSession(HttpServletRequest request){
        return request.getSession();
    }

    public static Object getAttribute(HttpServletRequest request,String str){
        return getSession(request).getAttribute(str);
    }

    /**
     * 获取当前登录的用户
     * @param request
     * @return
     */
    public static UserVo getCurrentUser(HttpServletRequest request){
        UserVo user = (UserVo) getAttribute(request,USER_KEY);
        return user;
    }

    /**
     * 获取当前登录的用户id
     * @param request
     * @return
     */
    public static String getCurrentUserId(HttpServletRequest request){
        return getCurrentUser(request).getUserId();
    }
}
